package com.tw.community.helpers{
	import mx.core.Application;
	import mx.core.UIComponent;
	
	

	/**
	 * 
	 * @author Ben Bishop
	 * This class is a quick and dirty way to manage screens in a Flex application
	 * 
	 */	
	public class ScreenManager{
		protected static var uiManager:ScreenManager
		//singleton pattern
		public static function getInstance():ScreenManager {
			if ( uiManager == null )
				uiManager = new ScreenManager();
			return uiManager;
		}
		public function ScreenManager(){
			
		}
		/**
		 * 
		 * @param c	The MXML/Class name you want to use as your screen
		 * 
		 */		
		public function setScreen(c:Class):void{
			var app:UIComponent = Application.application as UIComponent;
			//remove previous screen(s)
			while(app.numChildren > 0){
				app.removeChildAt(app.numChildren-1);
			}
			//attach new screen to the application
			app.addChild(new c());
		}
	}
}